﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CMS_GYM
{
    class clsLichChiTietDAO
    {
        #region Attribute
        /// <summary>
        /// Kết nối SQL Server
        /// </summary>
        private CSQLServer sqlServer = new CSQLServer();
        #endregion

        /// <summary>
        /// Lấy danh sách chức năng
        /// </summary>
        public DataTable LayBang()
        {
            string sql = "sp_GetBangLichChiTiet";
            DataTable dt = sqlServer.readData(sql);
            return dt;
        }

        public DataTable LayBangTheoSanCauId(int SanCauId)
        {
            string sql = "sp_GetBangLichChiTietTheoSanCauId";
            string[] ParameterColection = new string[1]{"@SanCauId"};
            Object[] valueofParameter = new Object[1]{SanCauId};
            DataTable dt = sqlServer.readData(sql, ParameterColection, valueofParameter);
            return dt;
        }

        public DataTable LayBangKetToanCauLong()
        {
            string sql = "sp_GetBangKetToanCauLong";
            DataTable dt = sqlServer.readData(sql);
            return dt;
        }

        public DataTable LayBangThongBaoTienSanHangThang()
        {
            string sql = "sp_ThongBaoTienSanCauLongHangThang";
            DataTable dt = sqlServer.readData(sql);
            return dt;
        }

       /// Thêm chức năng
       /// </summary>
       /// <param name="ChucNang"></param>
       /// <returns></returns>
        public int Them(clsLichChiTietDTO LichChiTiet)
        {
            int i = -1;
            string sql = "sp_InsertLichChiTiet";
            string[] ParameterColection = new string[5];
            Object[] valueofParameter = new Object[5];
            ParameterColection[0] = "@LichId";
            valueofParameter[0] = LichChiTiet.LichId;
            ParameterColection[1] = "@NgayTrongTuanId";
            valueofParameter[1] = LichChiTiet.NgayTrongTuanId;
            ParameterColection[2] = "@GioBatDau";
            valueofParameter[2] = LichChiTiet.GioBatDau;
            ParameterColection[3] = "@GioKetThuc";
            valueofParameter[3] = LichChiTiet.GioKetThuc;
            ParameterColection[4] = "@MoTa";
            valueofParameter[4] = LichChiTiet.MoTa;
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        /// <summary>
        /// Sửa thông tin chức năng
        /// </summary>
        /// <param name="LichChiTiet">
        /// MaChucNang  nvarchar(10)
        /// TenChucNang  nvarchar(255)
        /// </param>
        public int Sua(clsLichChiTietDTO LichChiTiet)
        {
            int i = -1;
            string sql = "sp_UpdateLichChiTiet";
            string[] ParameterColection = new string[6];
            Object[] valueofParameter = new Object[6];

            ParameterColection[0] = "@LichId";
            valueofParameter[0] = LichChiTiet.LichId;
            ParameterColection[1] = "@NgayTrongTuanId";
            valueofParameter[1] = LichChiTiet.NgayTrongTuanId;
            ParameterColection[2] = "@GioBatDau";
            valueofParameter[2] = LichChiTiet.GioBatDau;
            ParameterColection[3] = "@GioKetThuc";
            valueofParameter[3] = LichChiTiet.GioKetThuc;
            ParameterColection[4] = "@LichChiTietId";
            valueofParameter[4] = LichChiTiet.LichChiTietId;
            ParameterColection[5] = "@MoTa";
            valueofParameter[5] = LichChiTiet.MoTa;

            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        /// <summary>
        /// Xóa chức năng
        /// </summary>
        /// <param name="MaChucNang">Mã chức năng</param>
        public int Xoa(int LichChiTietId)
        {
            int i = -1;
            string sql = "sp_DeleteLichChiTiet";
            string[] ParameterColection = new string[1];
            Object[] valueofParameter = new Object[1];
            ParameterColection[0] = "@LichChiTietId";
            valueofParameter[0] = LichChiTietId;
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }
    }
}
